# -*- coding: utf-8 -*-
'''
Created on 2011. 3. 7.

@author: blueneti
'''

# wxPython용 모듈 
import wx
import wx.grid

#추후에 계속 컨트롤를 추가하게됨

class LottoAddEditFrame(wx._windows.Frame):
#class LottoAddEditFrame(wx.Dialog):
    def __init__(self, parent, wID, title):
        #부모의 wx._windows.Frame의 생성자를 호출
        wx._windows.Frame.__init__(self, parent, wID, title,
                                    wx.DefaultPosition,
                                    wx.Size(210, 180))
 
        #기본 패널 생성 및 초기화
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour(wx.Color(255,255,255))
        panel.SetAutoLayout(True)
        
        topPanel = wx.Panel(panel, -1)
        bottomPanel = wx.Panel(panel, -1)
        
        # 컨트롤 생성 및 초기화
        staticOwner = wx.StaticText(topPanel, -1, '소유자: ')
        
        self.search = wx.SearchCtrl(topPanel, -1, size=(110,-1))
        search = self.search
        search.ShowSearchButton(True)
        search.ShowCancelButton(True)
        
        menu = wx.Menu()
        search.SetMenu(menu)
        
        comboList = ['월', '화', '수', '목', '금', '토', '일']
        
        comboBoxWday = wx.ComboBox(topPanel, -1, '', wx.DefaultPosition, wx.DefaultSize, comboList)
        self.comboBoxWday = comboBoxWday
        
        gridNumbers = wx.grid.Grid(panel,-1)
        gridNumbers.CreateGrid(5, 6)
        #self.gridNumbers.DisableDragCell()
        gridNumbers.DisableDragColSize()
        gridNumbers.DisableDragRowSize()
        #header
        gridNumbers.SetRowLabelSize(30) # 위쪽 가로(row)의 라벨 크기
        gridNumbers.SetColLabelSize(1)  # 왼쪽 세로(column) 방향 라벨 크기
        
        gridNumbers.SetScrollbar(wx.VERTICAL, 0, 6, 50)
        gridNumbers.EnableScrolling(True, True)
        
        for i in range(6):
            gridNumbers.SetColLabelValue(i, '') # 왼쪽 세로 방향 라벨 이름을 빈공간으로 설정
            gridNumbers.SetColSize(i, 25)       # 위쪽 가로 방향 세로 길이 설정
        
        #gridNumbers.UpdateDimensions()
        
        buttonCancel = wx.Button(bottomPanel, -1, '취소')
        buttonDone   = wx.Button(bottomPanel, -1, '확인')
        
        #Box안에 수평 방향으로 채워넣음        
        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox = wx.BoxSizer(wx.HORIZONTAL)
        hboxBottom = wx.BoxSizer(wx.HORIZONTAL)
        
        #컨트롤 배열
        #flag = wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL
        flag = wx.ALIGN_CENTER
        
        hbox.Add(staticOwner, 0, flag|wx.ADJUST_MINSIZE)
        hbox.Add(search, 1, flag)
        hbox.Add((3,-1))
        hbox.Add(comboBoxWday, 0, flag|wx.ADJUST_MINSIZE)
        
        topPanel.SetSizer(hbox)
        
        hboxBottom.Add(buttonCancel, 1, flag)
        hboxBottom.Add(buttonDone, 1, flag)
        
        bottomPanel.SetSizer(hboxBottom)
        
        vbox.Add((-1,5))# space
        vbox.Add(topPanel, 0,flag)
        vbox.Add((-1,3))# space
        #vbox.Add(gridNumbers, 1,flag)
        #vbox.Add(gridNumbers, 1,flag|wx.SHAPED)
        vbox.Add(gridNumbers, 1,flag|wx.EXPAND)
        vbox.Add((-1,3))# space
        vbox.Add(bottomPanel, 0, flag)
        vbox.Add((-1,3))# space
        
        panel.SetSizer(vbox)
        
        gridNumbers.FitInside()
        #gridNumbers.Fit()
        #panel.Fit()
        
        #Event 핸들러 등록
        #Frame닫힐 때에 OnCloseWindow를 호출하여 instance 종료함
        wx.EVT_CLOSE(self, self.OnCloseWindow)
    
    
    def OnCloseWindow(self, event):
        self.Destroy()
        
    def getOwner(self):
        return self.search.GetValue()
    
    def setOwner(self, owner):
        self.search.SetValue(owner)
    
    def getWeek(self):
        return self.comboBoxWday.GetValue()
    
    def setWeek(self, week):
        self.comboBoxWday.SetValue(week)
    
    def getNumbers(self):
        pass
    
    def setNumbers(self, numList):
        pass
    
    

class MyApp(wx.App):
    def __init__(self, redirect=False):
        wx.App.__init__(self, redirect)

    def OnInit(self):
        # Frame 생성
        frame = LottoAddEditFrame(None, -1, "Test")
        frame.Center() # 화면 중앙에 배치
        frame.Show(True)
        self.SetTopWindow(frame)
        return True


if __name__ == '__main__':
    app = MyApp() #객체 생성
    app.MainLoop() # event 처리하는 무한 루프